<template>
<div id="TxSq" class="page-blank">
  <van-nav-bar title="提现审批" left-arrow @click-left="goBack()"/>
  <van-tabs v-model="active" @change="changeType()" style="flex-shrink: 0; padding: 10px 0;" inverse 
    indicator-color="#18a3dc" color="#18a3dc" text-color="rgba(0, 0, 0, 0.54)" center type="card">
    <van-tab title="代理"></van-tab>
    <van-tab title="渠道商"></van-tab>
    <van-tab title="商户"></van-tab>
  </van-tabs>   
  <div class="flex-body">
    <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="getList">
      <div class="tongji-box" v-for="(item, index) in list" :key="index">
        <div class="tongji-item">
          <div class="tongji-row" style="height: 0.8rem;">
            <div style="font-size: 0.3rem;">{{ item.withdrawalRecordId }}</div>
            <!-- <div style="width: 3rem;">
              <van-button @click="shenghe( item, 1, index )" type="warning" style="width: 1.2rem; height: 0.6rem; line-height: 0.6rem;">通过</van-button>
              <van-button @click="shenghe( item, 2, index )" type="warning" style="width: 1.2rem; height: 0.6rem; line-height: 0.6rem; margin-left: 0.5rem;">拒绝</van-button>
            </div> -->
            <div style="width: 3rem;">
              <div @click="shenghe( item, 1, index )" class="btn_style">通过</div>
              <div @click="shenghe( item, 2, index )" class="btn_style" style="margin-left: 0.5rem;">拒绝</div>
            </div>
          </div>
          <div class="tongji-row">
            <div>申请时间：</div>
            <div>{{ item.createTime }}</div>
          </div>
          <div class="tongji-row">
            <div>账户类型：</div>
            <div>{{ typeArr[ item.withdrawalWay ] }}</div>
          </div>
          <div class="tongji-row">
            <div>提现金额：</div>
            <div>{{ item.withdrawalAmount }}</div>
          </div>
          <div class="tongji-row">
            <div>到账金额：</div>
            <div>{{ item.actualAmount }}</div>
          </div>
          <div class="tongji-row">
            <div>手续费率：</div>
            <div>{{ item.serviceChargeRatio }}</div>
          </div>
          <div v-if="userInfo.roleType == 0" class="tongji-row">
            <div>用户名：</div>
            <div>{{ item.userName }}</div>
          </div>
          <div v-if="userInfo.roleType == 0" class="tongji-row">
            <div>userId：</div>
            <div>{{ item.userId }}</div>
          </div>
          <div v-if="userInfo.roleType == 0" class="tongji-row">
            <div>用户角色：</div>
            <div>{{ item.userType }}</div>
          </div>
          <div v-if="userInfo.roleType == 0" class="tongji-row">
            <div>手机号：</div>
            <div>{{ item.userPhone }}</div>
          </div>
          <div v-if="userInfo.roleType == 0" class="tongji-row">
            <div>订单号：</div>
            <div>{{ item.wxPartnerTradeNo }}</div>
          </div>
          <div v-if="userInfo.roleType == 0" class="tongji-row">
            <div>付款单号：</div>
            <div>{{ item.wxPaymentNo }}</div>
          </div>
        </div>
      </div>
    </van-list>
  </div>  
</div>
</template>

<script lang="ts">
import { Vue, Component } from 'vue-property-decorator';
import axios from '@/utils/request';

@Component
export default class TxSq extends Vue {
  active: number = 0

  userInfo: any = {}

  list: any = []

  loading: boolean = false
  finished: boolean = false
  page: any = 1
  searchValue: any = ''

  typeArr: any = [ '银行卡', '支付宝', '微信' ]

  changeType() {
    this.list = [];
    this.page = 1;
    this.loading = false;
    this.finished = false;
  }
  
  getList() {
    let page = this.page, size = 10, findSubordinate = true;
    let active = this.active;
    let roleTypeList: any = [ 1, 4, 3 ];
    let roleType = roleTypeList[ active ];
    axios.post('/api/WithdrawController/getWithdrawList', { 
      query: { page, size },
      body: { withdrawalStatus: 0, roleType }
    }).then((res: any) => {
      if(active != this.active) return ;
      let json = res || {};
      let list = json.list || [];
      this.page = page + 1;
      this.loading = false;
      this.list.push( ...list );
      if(json.isLastPage) this.finished = true;
    }).catch((err: any) => {
      this.loading = false;
      this.finished = true;
    });
  }
  
  shenghe(item: any, withdrawalStatus: any, index: any) {     
    axios.post('/api/WithdrawController/auditWithdraw', {  
      query: { withdrawalStatus, withdrawalRecordId: item.withdrawalRecordId }
    }).then((res: any) => {      
      if(withdrawalStatus == 1) this.$toast('已通过该申请');
      else this.$toast('已拒绝该申请');
      this.list.splice(index, 1);
    });
  }

  goBack() {
    this.$router.go(-1);
  }

  mounted() {
    this.userInfo = this.$store.state.userInfo;
  }
  
};
</script>

